package com.ruoyi.system.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.HttpUtil;
import com.ruoyi.common.utils.http.HttpHelper;
import com.ruoyi.common.utils.http.HttpUtilOcr;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.system.domain.vo.ScenicPointVo;
import com.ruoyi.system.domain.vo.ScenicRouteVo;
import com.ruoyi.system.domain.vo.ScenicSpotVo;
import com.ruoyi.system.service.IFeginOutService;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 调用外部
 */
@Service
public class FeginOutServiceImpl  implements IFeginOutService {


    private String host ="https://yubei-guide.cqybmap.cn/yubei";

    @Override
    public Boolean syncScenicSpot(ScenicSpotVo scenicSpotVo) {


        String path = "/pb/sync/scenicSpot";
        String method = "POST";
        Map<String, String> headers = new HashMap<String, String>();
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/json; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
//          scenicSpotVo.setId((long)123455667);
//          scenicSpotVo.setLatitude(12.33);
//          scenicSpotVo.setLongitude(12.33);
//          scenicSpotVo.setName("测试数据");
//          scenicSpotVo.setPicture("qwwqwqdewdew");
//          scenicSpotVo.setVoiceContent("12sdeededefef");
//          scenicSpotVo.setVoice("qwwererrttt");
//          scenicSpotVo.setPriority(0);
//          scenicSpotVo.setBrief("123");

        System.out.println(JSON.toJSONString(scenicSpotVo));
        try {
            HttpResponse httpResponse= HttpUtilOcr.doPost(host,path,method,headers,querys,JSON.toJSONString(scenicSpotVo));
            String res = EntityUtils.toString(httpResponse.getEntity());
            System.out.println(res);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Boolean deleteScenicSpot(Long id) {
        String path = "/pb/sync/scenicSpot/"+id;
        String method = "POST";
        Map<String, String> headers = new HashMap<String, String>();
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/json; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();


        try {
            HttpResponse httpResponse=  HttpUtilOcr.doDelete(host,path,method,headers,querys);
            String res = EntityUtils.toString(httpResponse.getEntity());
            System.out.println(res);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

    @Override
    public Boolean syncServicePoint(ScenicPointVo scenicPointVo) {


        String path = "/pb/sync/servicePoint";
        String method = "POST";
        Map<String, String> headers = new HashMap<String, String>();
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/json; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
        System.out.println(JSON.toJSONString(scenicPointVo));
        try {
            HttpResponse httpResponse= HttpUtilOcr.doPost(host,path,method,headers,querys,JSON.toJSONString(scenicPointVo));
            String res = EntityUtils.toString(httpResponse.getEntity());
            System.out.println(res);

        } catch (Exception e) {
            e.printStackTrace();
        }





        return null;
    }

    @Override
    public Boolean deleteServicePoint(Long id) {

        String path = "/pb/sync/servicePoint/"+id;
        String method = "POST";
        Map<String, String> headers = new HashMap<String, String>();
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/json; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
        try {
            HttpResponse httpResponse=  HttpUtilOcr.doDelete(host,path,method,headers,querys);
            String res = EntityUtils.toString(httpResponse.getEntity());
            System.out.println(res);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Boolean syncScenicRoute(ScenicRouteVo scenicRouteVo) {

        String path = "/pb/sync/scenicRoute";
        String method = "POST";
        Map<String, String> headers = new HashMap<String, String>();
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/json; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
        System.out.println(JSON.toJSONString(scenicRouteVo));
        try {
            HttpResponse httpResponse= HttpUtilOcr.doPost(host,path,method,headers,querys,JSON.toJSONString(scenicRouteVo));
            String res = EntityUtils.toString(httpResponse.getEntity());
            System.out.println(res);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Boolean deleteScenicRoute(Long id) {
        String path = "//pb/sync/scenicRoute/"+id;
        String method = "POST";
        Map<String, String> headers = new HashMap<String, String>();
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/json; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
        try {
            HttpResponse httpResponse=  HttpUtilOcr.doDelete(host,path,method,headers,querys);
            String res = EntityUtils.toString(httpResponse.getEntity());
            System.out.println(res);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}
